<template>
  <div class="app">
    <topBackBar
      Text="修改资料"
      @click="$router.push({ name: 'Mycenter' })"
    ></topBackBar>

    <van-cell-group class="Text" v-if="type == 'text'">
      <van-field v-model="value" label="修改文本" />
    </van-cell-group>
    <!-- 输入密码 -->
    <van-field v-model="value" type="password" label="修改密码" v-else />
    <van-button color="#728800" plain @click="update(property)"
      >确认修改</van-button
    >
  </div>
</template>

<script>
import topBackBar from './topBackBar'

export default {
  data() {
    return {
      value: '',
      property: '',
      type: '',
      id: ''
    }
  },
  components: {
    topBackBar
  },
  methods: {
    update(prop) {
      console.log(this.property)
      this.$axios({
        url: `/user_update/${this.id}`,
        method: 'POST',
        data: { [prop]: this.value }
      }).then(res => {
        if (res.statusText === 'OK') {
          this.$toast.success('修改成功')
          setTimeout(() => {
            this.$router.push({ name: 'edit' })
          }, 1000)
        } else {
          this.$toast.success('修改失败')
        }
      })
    }
  },
  created() {
    this.value = this.$route.params.TextValue
    this.type = this.$route.params.type
    this.id = this.$route.params.id
    this.property = this.$route.params.property
  }
}
</script>

<style lang="less" scoped>
.app {
  height: 100vh;
  background-color: rgb(238, 238, 190);
}
</style>
